<?php 
namespace app\admin\controller;
class ClientReview extends Common
{
	function _initialize()
	{
		
	}

	function reviewList()
	{
		@$status = input()['status']?input()['status']:0;
		$keywords = input('keywords');
		$list = db('client')
				->alias('c')
				->field('c.*,a.name as aname')
				->join('admin a','a.id=c.xaid')
				->where('c.status',4)
				->order('id DESC');
		$count = db('client')->where('status',4);
		if($status == 1 OR $status == -1)
		{
			$list = $list->where('c.review_status',$status);
			$count = $count->where('review_status',$status);
		}
		if($keywords)
		{
			$list = $list->where('c.activity','LIKE',"%{$keywords}%");
			$count = $count->where('activity','LIKE',"%{$keywords}%");
		}
		$list = $list->paginate(10,false,['query'=>$this->request->param()]);
		$count = $count->count();

        $this->assign([
            'list'=>$list,
            'count'=>$count,
            'status'=>$status
        ]);
        return view();
	}

	function view()
	{
		$clientId = input()['client_id'];
    	$clientInfo = db('client')->where('id',$clientId)->find();
    	$reviewInfo = db('client_review')->where('client_id',$clientId)->find();


    	//idToAdminname

    	$this->assign([
    		'clientInfo'=>$clientInfo,
    		'reviewInfo'=>$reviewInfo,

    	]);
        return view();
	}

	function edit()
	{
        if(request()->isAjax()){
            $data=input('post.')['data'];
            $data['admin_id'] = session('uid','','admin');
            $data['dotime'] = time();
            $data['content'] = str_replace(PHP_EOL, '<br>', $data['content']);
            $data['other_content'] = str_replace(PHP_EOL, '<br>', $data['other_content']);
            //print_r($data);exit;
            $save=db('client_review')->insert($data);
            if($save !== false){
            	db('client')->where('id',$data['client_id'])->update(['review_status'=>1,'review_time'=>time()]);
                return ['msg'=>'提交成功','icon'=>1];
            }else{
                return ['msg'=>'提交失败','icon'=>2];
            }
            return;
        }
		$clientId = input()['client_id'];
    	$clientInfo = db('client')->where('id',$clientId)->find();

    	$this->assign([
    		'clientInfo'=>$clientInfo,

    	]);
        return view();
	}

}